package com.share.service.template;

import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.share.bean.template.TemplateItem;
import com.share.commons.base.dao.BaseDaoSupport;

@Component
@Transactional
public class TemplateItemServiceImpl extends BaseDaoSupport<TemplateItem> implements TemplateItemService{

	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public void delete(int id) throws RuntimeException {
		this.deleteObject(TemplateItem.class, id) ;
	}

	@SuppressWarnings("unchecked")
	@Override
	@Transactional(readOnly=true,propagation=Propagation.NOT_SUPPORTED)
	public List find() throws RuntimeException {
		String hql = "select o from TemplateItem o" ;
		
		return (List) this.find(hql) ;
	}

	@Override
	@Transactional(readOnly=true,propagation=Propagation.NOT_SUPPORTED)
	public Object loadById(int id) throws RuntimeException {
		return this.loadById(TemplateItem.class, id) ;
	}

	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public void save(Object entity) throws RuntimeException {
		TemplateItem t = (TemplateItem)entity ;
		t.setAddTime(new Date()) ;
		this.saveObject(t) ;
	}

	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public void update(Object entity) throws RuntimeException {
		TemplateItem t = (TemplateItem)entity ;
		t.setAddTime(new Date()) ;
		this.updateObject((TemplateItem) entity) ;
	}


}
